<template>
  <el-drawer v-model="addDrawer" size="50%" :show-close="false" @opened="openDrawer" @close="closeDrawer">
    <template #title>
      <h2><svg-icon icon-class="list"></svg-icon><span style="padding-left: 15px">{{ formName }}</span></h2>
      <el-button type="primary" @click="confirmAndSave" :disabled="drawerLoading" v-if="!form[idName]">保存&继续填写</el-button>
      <el-button type="primary" @click="confirmClick" :disabled="drawerLoading" v-if="!(route.path.includes('dataIntegrate') || route.path.includes('achievementSearch'))">保存</el-button>
    </template>
    <template #default>
      <el-form :model="form" ref="addRef" :inline="true" :rules="formRules" label-width="160px" v-loading="drawerLoading">
        <el-row justify="space-between">
          <el-form-item label="省" prop="provinceId" v-if="provinceData.length > 0 || form.provinceId">
            <el-select v-model="form.provinceId" placeholder="请选择省" @change="chooseFormProvince" clearable>
              <el-option v-for="item in provinceData" :key="item.id" :label="item.name" :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="省" v-else>
            <el-input v-model="form.province" clearable disabled></el-input>
          </el-form-item>
          <el-form-item label="市" prop="cityId" v-if="provinceData.length > 0 || form.cityId">
            <el-select v-model="form.cityId" placeholder="请选择市" @change="chooseFormCity" clearable>
              <el-option v-for="item in cityData" :key="item.id" :label="item.name" :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="市" v-else>
            <el-input v-model="form.city" clearable disabled></el-input>
          </el-form-item>
        </el-row>
        <el-row justify="space-between">
          <el-form-item label="区/县" prop="countyId" v-if="provinceData.length > 0 || form.countyId">
            <el-select v-model="form.countyId" placeholder="请选择区/县" @change="chooseFormCounty" clearable>
              <el-option v-for="item in areaData" :key="item.id" :label="item.name" :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="区/县" v-else>
            <el-input v-model="form.county" clearable disabled></el-input>
          </el-form-item>
          <el-form-item label="目标区编号" prop="targetRegionId">
            <el-input v-model="form.targetRegionId" placeholder="请输入目标区编号" clearable maxlength="17"></el-input>
          </el-form-item>
        </el-row>
        <el-row justify="space-between">
          <el-form-item label="点编号" prop="pointId">
            <el-input v-model="form.pointId" placeholder="请输入点编号" clearable maxlength="17"></el-input>
          </el-form-item>
        </el-row>
        <el-row justify="space-between">
          <el-form-item label="三分量位移时程图原始编号" prop="seismUgraphArwid" style="width:100%">
            <el-space direction="vertical" alignment="flex-start" :size="15" class="upload-space">
              <el-input v-model="form.seismUgraphArwid" placeholder="请输入三分量位移时程图原始编号" clearable maxlength="20"></el-input>
              <FileUpload v-model="form.seismUgraphArwFileid" @uploadFile="uploadSuccess('seismUgraphArwFileid', $event)"
                @delFile="deleteFile('seismUgraphArwFileid', $event)" />
            </el-space>
          </el-form-item>
        </el-row>
        <el-row justify="space-between">
          <el-form-item label="位移时程数据文件原始编号" prop="seismUdataArwid" style="width:100%">
            <el-space direction="vertical" alignment="flex-start" :size="15" class="upload-space">
              <el-input v-model="form.seismUdataArwid" placeholder="请输入位移时程数据文件原始编号" clearable maxlength="20"></el-input>
              <FileUpload v-model="form.seismUdataArwFileid" @uploadFile="uploadSuccess('seismUdataArwFileid', $event)"
                @delFile="deleteFile('seismUdataArwFileid', $event)" />
            </el-space>
          </el-form-item>
        </el-row>
        <el-row justify="space-between">
          <el-form-item label="速度时程图原始编号" prop="seismVgraphArwid" style="width:100%">
            <el-space direction="vertical" alignment="flex-start" :size="15" class="upload-space">
              <el-input v-model="form.seismVgraphArwid" placeholder="请输入速度时程图原始编号" clearable maxlength="20"></el-input>
              <FileUpload v-model="form.seismVgraphArwFileid" @uploadFile="uploadSuccess('seismVgraphArwFileid', $event)"
                @delFile="deleteFile('seismVgraphArwFileid', $event)" />
            </el-space>
          </el-form-item>
        </el-row>
        <el-row justify="space-between">
          <el-form-item label="加速度时程数据文件原始编号" prop="seismVdataArwid" style="width:100%">
            <el-space direction="vertical" alignment="flex-start" :size="15" class="upload-space">
              <el-input v-model="form.seismVdataArwid" placeholder="请输入加速度时程数据文件原始编号" clearable maxlength="20"></el-input>
              <FileUpload v-model="form.seismVdataArwFileid" @uploadFile="uploadSuccess('seismVdataArwFileid', $event)"
                @delFile="deleteFile('seismVdataArwFileid', $event)" />
            </el-space>
          </el-form-item>
        </el-row>
        <el-row justify="space-between">
          <el-form-item label="加速度时程图原始编号" prop="seismAgraphArwid" style="width:100%">
            <el-space direction="vertical" alignment="flex-start" :size="15" class="upload-space">
              <el-input v-model="form.seismAgraphArwid" placeholder="请输入加速度时程图原始编号" clearable maxlength="20"></el-input>
              <FileUpload v-model="form.seismAgraphArwFileid" @uploadFile="uploadSuccess('seismAgraphArwFileid', $event)"
                @delFile="deleteFile('seismAgraphArwFileid', $event)" />
            </el-space>
          </el-form-item>
        </el-row>
        <el-row justify="space-between">
          <el-form-item label="加速度时程数据文件原始编号" prop="seismAdataArwid" style="width:100%">
            <el-space direction="vertical" alignment="flex-start" :size="15" class="upload-space">
              <el-input v-model="form.seismAdataArwid" placeholder="请输入加速度时程数据文件原始编号" clearable maxlength="20"></el-input>
              <FileUpload v-model="form.seismAdataArwFileid" @uploadFile="uploadSuccess('seismAdataArwFileid', $event)"
                @delFile="deleteFile('seismAdataArwFileid', $event)" />
            </el-space>
          </el-form-item>
        </el-row>
        <el-row justify="space-between">
          <el-form-item label="位移反应谱图原始编号" prop="spectrumUgraphArwid" style="width:100%">
            <el-space direction="vertical" alignment="flex-start" :size="15" class="upload-space">
              <el-input v-model="form.spectrumUgraphArwid" placeholder="请输入位移反应谱图原始编号" clearable
                maxlength="20"></el-input>
              <FileUpload v-model="form.spectrumUgraphArwFileid"
                @uploadFile="uploadSuccess('spectrumUgraphArwFileid', $event)"
                @delFile="deleteFile('spectrumUgraphArwFileid', $event)" />
            </el-space>
          </el-form-item>
        </el-row>
        <el-row justify="space-between">
          <el-form-item label="位移反应谱数据文件原始编号" prop="spectrumUdataArwid" style="width:100%">
            <el-space direction="vertical" alignment="flex-start" :size="15" class="upload-space">
              <el-input v-model="form.spectrumUdataArwid" placeholder="请输入位移反应谱数据文件原始编号" clearable
                maxlength="20"></el-input>
              <FileUpload v-model="form.spectrumUdataArwFileid"
                @uploadFile="uploadSuccess('spectrumUdataArwFileid', $event)"
                @delFile="deleteFile('spectrumUdataArwFileid', $event)" />
            </el-space>
          </el-form-item>
        </el-row>
        <el-row justify="space-between">
          <el-form-item label="速度反应谱图原始编号" prop="spectrumVgraphArwid" style="width:100%">
            <el-space direction="vertical" alignment="flex-start" :size="15" class="upload-space">
              <el-input v-model="form.spectrumVgraphArwid" placeholder="请输入速度反应谱图原始编号" clearable
                maxlength="20"></el-input>
              <FileUpload v-model="form.spectrumVgraphArwFileid"
                @uploadFile="uploadSuccess('spectrumVgraphArwFileid', $event)"
                @delFile="deleteFile('spectrumVgraphArwFileid', $event)" />
            </el-space>
          </el-form-item>
        </el-row>
        <el-row justify="space-between">
          <el-form-item label="速度反应数据文件原始编号" prop="spectrumVdataArwid" style="width:100%">
            <el-space direction="vertical" alignment="flex-start" :size="15" class="upload-space">
              <el-input v-model="form.spectrumVdataArwid" placeholder="请输入速度反应数据文件原始编号" clearable
                maxlength="20"></el-input>
              <FileUpload v-model="form.spectrumVdataArwFileid"
                @uploadFile="uploadSuccess('spectrumVdataArwFileid', $event)"
                @delFile="deleteFile('spectrumVdataArwFileid', $event)" />
            </el-space>
          </el-form-item>
        </el-row>
        <el-row justify="space-between">
          <el-form-item label="加速度反应谱图原始编号" prop="spectrumAgraphArwid" style="width:100%">
            <el-space direction="vertical" alignment="flex-start" :size="15" class="upload-space">
              <el-input v-model="form.spectrumAgraphArwid" placeholder="请输入加速度反应谱图原始编号" clearable
                maxlength="20"></el-input>
              <FileUpload v-model="form.spectrumAgraphArwFileid"
                @uploadFile="uploadSuccess('spectrumAgraphArwFileid', $event)"
                @delFile="deleteFile('spectrumAgraphArwFileid', $event)" />
            </el-space>
          </el-form-item>
        </el-row>
        <el-row justify="space-between">
          <el-form-item label="加速度反应谱数据文件原始编号" prop="spectrumAdataArwid" style="width:100%">
            <el-space direction="vertical" alignment="flex-start" :size="15" class="upload-space">
              <el-input v-model="form.spectrumAdataArwid" placeholder="请输入加速度反应谱数据文件原始编号" clearable
                maxlength="20"></el-input>
              <FileUpload v-model="form.spectrumAdataArwFileid"
                @uploadFile="uploadSuccess('spectrumAdataArwFileid', $event)"
                @delFile="deleteFile('spectrumAdataArwFileid', $event)" />
            </el-space>
          </el-form-item>
        </el-row>
        <el-row justify="space-between">
          <el-form-item label="备注" prop="commentInfo" style="width:100%">
            <el-input v-model="form.commentInfo" placeholder="请输入备注" :autosize="{ minRows: 5, maxRows: 10 }"
              type="textarea" show-word-limit maxlength="2147483647" clearable></el-input>
          </el-form-item>
        </el-row>
      </el-form>
    </template>
  </el-drawer>
</template>
<script setup>
import useOtherData from '@/hooks/useOtherData'
const { route, form, queryData, formName, idName,
  uploadSuccess, deleteFile,
  chooseFormProvince, chooseFormCity, chooseFormCounty,
  addRef, confirmAndSave, addDrawer, confirmClick, checkIdValid, openDrawer, closeDrawer, drawerLoading } = useOtherData()

const { provinceData, cityData, areaData } = toRefs(queryData)

const formRules = reactive({
  provinceId: [{ required: true, message: '请选择省！', trigger: 'change' }],
  cityId: [{ required: true, message: '请选择市！', trigger: 'change' }],
  countyId: [{ required: true, message: '请选择区/县！', trigger: 'change' }],
  targetRegionId: [
    { required: true, message: '请输入目标区编号!', trigger: 'blur' },
    { min: 17, max: 17, message: '长度必须为17位', trigger: 'blur' },
    { validator: checkIdValid, trigger: 'blur' },
  ],
  pointId: [{ required: true, message: '请输入点编号!', trigger: 'blur' }]
})
</script>